<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数的定义与调用</title>
</head>
<body>
    <script>
        // 定义函数：计算1到100之间所有整数的和
        function getSum() {
            var sum = 0;
            for (var i = 1; i <= 100; i++) {
                sum += i;
            }
            return sum;
        }

        // 调用函数并将结果输出到 HTML 文档中
        document.write("1 到 100 个数相加和为：" + getSum());
    </script>
</body>
</html>